<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "project_files".
 *
 * @property string $id
 * @property string $filename
 * @property string $path
 * @property int $class
 * @property string $project_id
 * @property int $open_to_auth 是否对认证会员开放，1开放2不开放
 * @property string $created_at
 * @property string $updated_at
 *
 * @property Projects $project
 */
class ProjectFilesDjr extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'project_files';
    }

    /**
     * @return \yii\db\Connection the database connection used by this AR class.
     */
    public static function getDb()
    {
        return Yii::$app->get('forge');
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
//            [['filename', 'path', 'class', 'project_id'], 'required'],
            [['class', 'project_id', 'open_to_auth'], 'integer'],
            [['created_at', 'updated_at'], 'safe'],
            [['filename', 'path'], 'string', 'max' => 255],
//            [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Projects::className(), 'targetAttribute' => ['project_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'filename' => 'Filename',
            'path' => 'Path',
            'class' => 'Class',
            'project_id' => 'Project ID',
            'open_to_auth' => '是否对认证会员开放，1开放2不开放',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProject()
    {
        return $this->hasOne(Projects::className(), ['id' => 'project_id']);
    }

    /**
     * {@inheritdoc}
     * @return ProjectFilesDjrQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new ProjectFilesDjrQuery(get_called_class());
    }
}
